package com.itheima.Demo3Stream;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

public class StreamDemo1
{
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        list.add("张三");
        list.add("李四");
        list.add("王五");
        list.add("张四");
        //找出姓张的并且名字是两个字的 放到一个集合中去
        ArrayList<String> list2 = new ArrayList<>();
        for (String name : list) {
            if(name.startsWith("张")&& name.length()==2)
            {
                list2.add(name);
            }
        }
        System.out.println(list2);
        //运用stream流
        List<String> list3 = list.stream().filter(s -> s.startsWith("张")).filter(s -> s.length()==2).collect(Collectors.toList());
        System.out.println(list3);
    }
}
